﻿using System;
using System.Linq;
using System.Windows.Data;
using TweetSharp.Twitter.Model;

namespace Halfwit.Converters
{
    public class IsMentionConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var tweet = values[0] as TwitterStatus;
            if (tweet == null) return false;

            var screenName = values[1] as String;
            if (screenName == null) return false;

            if (screenName.StartsWith("@")) screenName = screenName.Substring(1);

            return tweet.TextMentions.Contains(screenName, StringComparer.OrdinalIgnoreCase);
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
